# Collect headers and sources
file(GLOB 3RDPARTY_HEADERS "${CMAKE_CURRENT_LIST_DIR}/3rdparty/*.h")
file(GLOB 3RDPARTY_SOURCES "${CMAKE_CURRENT_LIST_DIR}/3rdparty/*.cpp")
file(GLOB D_HEADERS "${PROJECT_SOURCE_DIR}/include/DDevice/*")
file(GLOB_RECURSE PUBLIC_HEADERS "${PROJECT_SOURCE_DIR}/include/*.h")
file(GLOB_RECURSE PRIVATE_HEADERS "${CMAKE_CURRENT_LIST_DIR}/lsdevice/*.h" "${CMAKE_CURRENT_LIST_DIR}/inputdevices/*.h")
file(GLOB_RECURSE DEVICE_SOURCES "${CMAKE_CURRENT_LIST_DIR}/lsdevice/*.cpp" "${CMAKE_CURRENT_LIST_DIR}/inputdevices/*.cpp")
list(APPEND PUBLIC_HEADERS ${D_HEADERS})

add_library(${LIB_NAME} SHARED
    ${3RDPARTY_HEADERS}
    ${3RDPARTY_SOURCES}
    ${PUBLIC_HEADERS}
    ${PRIVATE_HEADERS}
    ${DEVICE_SOURCES}
)

target_link_libraries(${LIB_NAME}
PUBLIC
    Qt${QT_VERSION_MAJOR}::Core
    Qt${QT_VERSION_MAJOR}::DBus
    Dtk${DTK_VERSION_MAJOR}::Core
PRIVATE
    PkgConfig::LibNl3
    PkgConfig::LibNl3Route
)

target_compile_definitions(${LIB_NAME} PRIVATE "LIBDTKDEVICE_LIBRARY")

target_include_directories(${LIB_NAME}
PUBLIC
    $<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}/include/global>
    $<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}/include/lsdevice>
    $<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}/include/inputdevices>
    $<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}/include/DDevice>
    $<BUILD_INTERFACE:${CMAKE_CURRENT_LIST_DIR}/3rdparty>
    $<BUILD_INTERFACE:${CMAKE_CURRENT_LIST_DIR}/inputdevices>
    $<BUILD_INTERFACE:${CMAKE_CURRENT_LIST_DIR}/inputdevices/dbus>
    $<BUILD_INTERFACE:${CMAKE_CURRENT_LIST_DIR}/lsdevice>
INTERFACE
    $<INSTALL_INTERFACE:${INCLUDE_INSTALL_DIR}>
)

target_link_directories(${LIB_NAME} INTERFACE
    $<BUILD_INTERFACE:${CMAKE_CURRENT_BINARY_DIR}>
    $<INSTALL_INTERFACE:${LIBRARY_INSTALL_DIR}>
)

set_target_properties(${LIB_NAME} PROPERTIES
    VERSION ${CMAKE_PROJECT_VERSION}
    SOVERSION ${CMAKE_PROJECT_VERSION_MAJOR}
    EXPORT_NAME Device
    PUBLIC_HEADER "${PUBLIC_HEADERS}"
)

install(TARGETS ${LIB_NAME} EXPORT DtkDeviceTargets DESTINATION ${LIBRARY_INSTALL_DIR} PUBLIC_HEADER DESTINATION ${INCLUDE_INSTALL_DIR})
install(EXPORT DtkDeviceTargets
    FILE Dtk${DTK_VERSION_MAJOR}DeviceTargets.cmake
    NAMESPACE Dtk${DTK_VERSION_MAJOR}::
    DESTINATION ${CMAKE_CONFIG_INSTALL_DIR}
)
